
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

/// @author: pengboboer
/// @createDate: 2022/8/23
/// 默认拒绝权限后去设置页的弹框
typedef ShowPermissionsDialogBuilder = void Function(BuildContext context,
    {required String hint, required String rightBtnText, required VoidCallback onClick});

ShowPermissionsDialogBuilder defaultShowPermisionsDialogBuilder = _showPermissionsDialog;

ShowPermissionsDialogBuilder _showPermissionsDialog =
    (BuildContext context, {required String hint, required String rightBtnText, required VoidCallback onClick}) {
  return _showDialog(context, hint: hint, rightBtnText: rightBtnText, onClick: onClick);
};

void _showDialog(BuildContext context, {required String hint, required String rightBtnText, required VoidCallback onClick}) {
  if (context == null) return;
  showDialog(
    context: context,
    builder: (ctx) {
      return Dialog(
        child: Container(
          width: 200.w,
          height: 200.w,
          color: Colors.white,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Padding(
                padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 40.w),
                child: Text(
                  hint,
                  style: TextStyle(
                    fontSize: 17.sp,
                  ),
                ),
              ),
              Row(
                children: [
                  Expanded(
                    child: ElevatedButton(
                      onPressed: () async {
                        Get.back();
                      },
                      child: Text("取消"),
                    ),
                  ),
                  Expanded(
                    child: ElevatedButton(
                      onPressed: onClick,
                      child: Text(rightBtnText),
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      );
    },
  );
}
